<?php


class m_history_saldo extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    function get($where = null, $limit = null) {
        if ($where != null)
            $this->db->where($where);
        return $this->db->get('history_saldo');
    }

    function get_id($nomer_order) {
        $this->db->where('NOMER_ORDER', $nomer_order);
        return $this->db->get('order_barang');
    }

    function update_saldo($perkiraan,$saldo,$date){
        $data = array(
            'KODE_PERKIRAAN' => $perkiraan,
            'SALDO_AWAL' => $saldo,
            'TGL_CATAT' => $date.'-01',
        );

        $this->db->where('KODE_PERKIRAAN', $perkiraan);
        $this->db->where('TGL_CATAT like', "$date%");
        $result = $this->db->get('history_saldo', $data);

        if ($result->num_rows() > 0){
            $id = $result->row()->ID_HISTORY_SALDO;
            $this->db->where('ID_HISTORY_SALDO', $id);
            $this->db->update('history_saldo', $data);
        }else
            $this->db->insert('history_saldo', $data);
    }

}
?>
